package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.vo.wx.search.SearchIndexVo;
import com.cskaoyan.service.wx.WxSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zjq
 * @date 2022/11/23 15:07
 */
@RestController
@RequestMapping("/wx/search")
public class WxSearchController {
    @Autowired
    WxSearchService wxSearchService;

    @GetMapping("/index")
    public BaseRespVo<SearchIndexVo> search() {

        SearchIndexVo keywords = wxSearchService.index();

        return BaseRespVo.ok(keywords);
    }
    /**
     * 动态显示搜索历史
     *
     * @param keyword 关键词
     * @return 搜索历史
     */
    @RequestMapping("/helper")
    public BaseRespVo<List<String>> helper(String keyword) {

        List<String> helper = wxSearchService.helper(keyword);
        return BaseRespVo.ok(helper);

    }

    /**
     * @author zjq
     * @date 2022/11/23 17:07
     */

    @RequestMapping("/clearhistory")
    public BaseRespVo clearhistory(){
        wxSearchService.cleanSearchHistory();
        return BaseRespVo.ok();
    }

}
